home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / qe4 / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-06  |  1.9 KB  |  121 lines

  1.  
  2. #include "qe3.h"
  3.  
  4. char    token[MAXTOKEN];
  5. qboolean    unget;
  6. char    *script_p;
  7. int        scriptline;
  8.  
  9. void    StartTokenParsing (char *data)
  10. {
  11.     scriptline = 1;
  12.     script_p = data;
  13.     unget = false;
  14. }
  15.  
  16. qboolean GetToken (qboolean crossline)
  17. {
  18.     char    *token_p;
  19.  
  20.     if (unget)                         // is a token allready waiting?
  21.         return true;
  22.  
  23. //
  24. // skip space
  25. //
  26. skipspace:
  27.     while (*script_p <= 32)
  28.     {
  29.         if (!*script_p)
  30.         {
  31.             if (!crossline)
  32.                 Error ("Line %i is incomplete",scriptline);
  33.             return false;
  34.         }
  35.         if (*script_p++ == '\n')
  36.         {
  37.             if (!crossline)
  38.                 Error ("Line %i is incomplete",scriptline);
  39.             scriptline++;
  40.         }
  41.     }
  42.  
  43.     if (script_p[0] == '/' && script_p[1] == '/')    // comment field
  44.     {
  45.         if (!crossline)
  46.             Error ("Line %i is incomplete\n",scriptline);
  47.         while (*script_p++ != '\n')
  48.             if (!*script_p)
  49.             {
  50.                 if (!crossline)
  51.                     Error ("Line %i is incomplete",scriptline);
  52.                 return false;
  53.             }
  54.         goto skipspace;
  55.     }
  56.  
  57. //
  58. // copy token
  59. //
  60.     token_p = token;
  61.  
  62.     if (*script_p == '"')
  63.     {
  64.         script_p++;
  65.         while ( *script_p != '"' )
  66.         {
  67.             if (!*script_p)
  68.                 Error ("EOF inside quoted token");
  69.             *token_p++ = *script_p++;
  70.             if (token_p == &token[MAXTOKEN])
  71.                 Error ("Token too large on line %i",scriptline);
  72.         }
  73.         script_p++;
  74.     }
  75.     else while ( *script_p > 32 )
  76.     {
  77.         *token_p++ = *script_p++;
  78.         if (token_p == &token[MAXTOKEN])
  79.             Error ("Token too large on line %i",scriptline);
  80.     }
  81.  
  82.     *token_p = 0;
  83.     
  84.     return true;
  85. }
  86.  
  87. void UngetToken (void)
  88. {
  89.     unget = true;
  90. }
  91.  
  92.  
  93. /*
  94. ==============
  95. TokenAvailable
  96.  
  97. Returns true if there is another token on the line
  98. ==============
  99. */
  100. qboolean TokenAvailable (void)
  101. {
  102.     char    *search_p;
  103.  
  104.     search_p = script_p;
  105.  
  106.     while ( *search_p <= 32)
  107.     {
  108.         if (*search_p == '\n')
  109.             return false;
  110.         if (*search_p == 0)
  111.             return false;
  112.         search_p++;
  113.     }
  114.  
  115.     if (*search_p == ';')
  116.         return false;
  117.  
  118.     return true;
  119. }
  120.  
  121.